package org.linuxgears.BouncingBall;

import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: khilkeol
 * Date: 31 ���� 2010
 * Time: 9:47:18
 * To change this template use File | Settings | File Templates.
 */
public class BallController {
    private BouncingBallModel model;

    public BallController(BouncingBallModel model) {
        this.model = model;
    }

    public void addBall() {
        this.addBall(BallFactory.getInstance().createColoredBall());
    }

    public void addBall(Point position) {
        this.addBall(BallFactory.getInstance().createColoredBall(), position);
    }

    public void addBall(Ball ball) {
        this.addBall(ball, (Point)BouncingBallModel.DEFAULT_POSITION.clone());
    }

    public void addBall(Ball ball, Point position) {
        model.addBall(ball, position);
    }

    public void selectNextBall() {
        model.selectNextBall();
    }

    public void selectPreviousBall() {
        model.selectPreviousBall();
    }

    public void deselectBall() {
        model.selectBall(null);
    }

    public void togglePause() {
        if (model.isPaused()) {
            model.resume();
        } else {
            model.pause();
        }
    }

	public void resetState() {
		model.resetState();
	}

	public void deleteSelectedBall() {
		model.removeBall(model.getActiveBallRunnable());
	}

	public void addInteractiveBall(Ball ball) {
		InteractiveMovingStrategy ims = new InteractiveMovingStrategy(model);
		
		model.addBall(ball, (Point)BouncingBallModel.DEFAULT_POSITION.clone(), ims);
		
		ims.startMovingTo(ball, new Point(200, 50));
		BallRunnable br = model.findBallRunnable(ball);
	}

	public void selectBallAt(Point position) {
		model.selectBallAt(position);
	}

	public void moveSelectedBallTo(Point newPosition) {
		if (model.getActiveBallRunnable() != null) {
			model.moveSelectedBallTo(newPosition);
		};
	}
}
